package cn.cjp.m3d27;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class bList {
    public static void main(String[] args) {
        //多态创建List集合
        List<String> list1 = new ArrayList<>();
        //List集合元素有序，允许存放重复元素
        list1.add("a");
        list1.add("b");
        list1.add("a");
        System.out.println(list1);
        System.out.println("================");

        //添加到指定位置
        list1.add(2,"c");
        System.out.println(list1);
        System.out.println("================");

        //移除指定位置的元素，返回被移除的元素
        String str1 = list1.remove(2);
        System.out.println(list1);
        System.out.println("================");

        //替换，返回被替换铁元素
        String str2 = list1.set(2,"A");
        System.out.println(list1);
        System.out.println("================");

        //List遍历
        for (int i = 0; i < list1.size(); i++) {
            System.out.println(list1.get(i));
        }
        System.out.println("================");

        Iterator<String> one = list1.listIterator();
        while(one.hasNext()){
            System.out.println(one.next());
        }
        System.out.println("================");

        for(String s :list1){
            System.out.println(s);
        }
    }
}
